package com.tomcov.client;


import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.tomcov.client.place.AppActivityMapper;
import com.tomcov.client.place.AppPlaceHistoryMapper;
import com.tomcov.client.place.WelcomPlace;
import com.tomcov.client.service.JourneyService;
import com.tomcov.client.service.JourneyServiceAsync;
import com.tomcov.client.service.MessageService;
import com.tomcov.client.service.MessageServiceAsync;
import com.tomcov.client.service.UserService;
import com.tomcov.client.service.UserServiceAsync;


public class Tomcov implements EntryPoint {
	
	 private Place defaultPlace = new WelcomPlace("TomCov");
	 private SimplePanel appWidget= new SimplePanel();
	 
	public void onModuleLoad() {
		
		//VerticalSplitPanel VSplitPanel = new VerticalSplitPanel();
		//appWidget = (SimplePanel) VSplitPanel.getTopWidget();
		//VSplitPanel.getBottomWidget();
		//VSplitPanel.setSplitPosition("40px");

		
		//GWT stuff
		appWidget.addStyleName("appWidget");
		UserServiceAsync USA = GWT.create(UserService.class);
		JourneyServiceAsync JSA = GWT.create(JourneyService.class);
		MessageServiceAsync MSA = GWT.create(MessageService.class);
		ClientFactory clientFactory = new ClientFactoryImpl(USA,JSA,MSA);
		
        EventBus eventBus = clientFactory.getEventBus();
        PlaceController placeController = clientFactory.getPlaceController();
        
        ActivityMapper activityMapper = new AppActivityMapper(clientFactory);
        ActivityManager activityManager = new ActivityManager(activityMapper, eventBus);
        activityManager.setDisplay(appWidget);
        
        AppPlaceHistoryMapper historyMapper= GWT.create(AppPlaceHistoryMapper.class);
        PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
        historyHandler.register(placeController, eventBus, defaultPlace);
        
        RootPanel.get().add(appWidget);
        historyHandler.handleCurrentHistory();

		
	}
}
